package com.exartisan.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.exartisan.bean.Gallery;
import com.exartisan.util.FontUtil;
import com.exartisan.yn_event.R;
import com.loopj.android.image.SmartImageView;

public class HomeGalleryAdapter extends BaseAdapter {
	private LayoutInflater inflater;
	private Context ctx;
	private ArrayList<Gallery> galleries;

	public HomeGalleryAdapter(Context context, ArrayList<Gallery> galleries) {
		inflater = LayoutInflater.from(context);
		this.ctx = context;
		this.galleries = galleries;
	}

	@Override
	public int getCount() {
		return galleries.size();
	}

	@Override
	public Object getItem(int pos) {
		return galleries.get(pos);
	}

	@Override
	public long getItemId(int pos) {
		return galleries.get(pos).getEventID();
	}

	@Override
	public View getView(int pos, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.gallery_category, null);
			holder.imgCover = (SmartImageView) convertView.findViewById(R.id.img_event);
			holder.tvCategoryName = (TextView) convertView.findViewById(R.id.tv_category_name);
			holder.tvCategoryName.setTypeface(FontUtil.loadFontFromAssets(ctx, FontUtil.TAHOMA));
			convertView.setTag(holder);
		} else
			holder = (ViewHolder) convertView.getTag();
		holder.imgCover.setImageUrl(galleries.get(pos).getThumbURL());
		holder.tvCategoryName.setText(galleries.get(pos).getEventName());
		
		
		//category.setLayoutParams(new GridView.LayoutParams(240, 240));
		
		return convertView;
	}
	
	class ViewHolder {
		SmartImageView imgCover;
		TextView tvCategoryName;
	}

}
